using System;
using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.Unity.Behaviour;
using HCore.Unity.Core;
using UI.UIMenu;
using UnityEngine;

namespace UI.UIGame.Menu
{
    public class OpenGamePageMenu : HCoreMonoBehaviour
    {
        private FunctionUpdater mFunctionUpdater;
        [Autowired] private UIMenuService mUIMenuService;

        private void Start()
        {
            Get().AddButtonClickListener(mUIMenuService.OpenSystemMenu);
        }

        private void OnEnable()
        {
            mFunctionUpdater = GameUtils.CreateKeyCodeAction(KeyCode.Escape, () => GameManager.DispatchRouter(Router.GamePageMenu));
        }

        private void OnDisable()
        {
            mFunctionUpdater?.DestroySelf();
        }
    }
}